﻿//  Copyright (c) 2011 Ray Liang (http://www.dotnetage.com)
//  Licensed MIT: http://www.opensource.org/licenses/mit-license.php

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace DNA.Mvc.Community
{
    /// <summary>
    /// Presents a forum and forum group.
    /// </summary>
    [Table("community_forums")]
    public class Forum
    {
        [Key]
        public virtual int ID { get; set; }

        /// <summary>
        /// Gets/Sets the forum title.
        /// </summary>
        [MaxLength(255),Required]
        public virtual string Title { get; set; }

        /// <summary>
        /// Gets/Sets the description text of the forum/forum group.
        /// </summary>
        [Column(TypeName="ntext")]
        public virtual string Description { get; set; }

        /// <summary>
        /// Gets/Sets the LastPostID. Default is null.
        /// </summary>
        public virtual int LastPostID { get; set; }

        /// <summary>
        /// Gets/Sets the parent forum/group id. Set to 0 as top level forum/group.
        /// </summary>
        [Required]
        public virtual int ParentID { get; set; }

        /// <summary>
        /// Gets/Sets allow anonymous view forum contents.
        /// </summary>
        [Required]
        public virtual bool AllowAnonymous { get; set; }

        /// <summary>
        /// Gets/Sets allows user to attach files to post.
        /// </summary>
        [Required]
        public virtual bool AllowAttachment { get; set; }

        /// <summary>
        /// Gets/Sets the forum lanugage. Default is en-US. 
        /// </summary>
        /// <remarks>
        /// Community will flter forums for current user language.
        /// </remarks>
        [MaxLength(50)]
        public virtual string Language 
        {
            get { return language; }
            set { language = value; }
        }

        private string language = "en-US";

        /// <summary>
        /// Gets/Sets whether this instance is a forum group
        /// </summary>
        [Required]
        public virtual bool IsGroup { get; set; }

        /// <summary>
        /// Gets/Sets whether the forum is locked.
        /// </summary>
        /// <remarks>
        /// When the forum is locked users could not allow post any new conents.
        /// </remarks>
        [Required]
        public virtual bool IsLocked { get; set; }

        /// <summary>
        /// Gets/Sets whether every post must be aduited before publish.
        /// </summary>
        [Required]
        public virtual bool IsModerated { get; set; }

        //public DateTime? LastPosted { get; set; }

        //[MaxLength(50)]
        //public virtual string LastPostedUser { get; set; }
        
        /// <summary>
        /// Gets/Sets the display position. Default is 0.
        /// </summary>
        [Required]
        public virtual int Pos { get; set; }

        [MaxLength(50)]
        public virtual string Theme { get; set; }

        /// <summary>
        /// Gets/Sets the total post count of the forum.
        /// </summary>
        [Required]
        public virtual int TotalPosts { get; set; }

        ///// <summary>
        ///// Gets/Sets the total thread count of the forum.
        ///// </summary>
        //[Required]
        //public virtual int TotalThreads { get; set; }

        /// <summary>
        /// Gets/Sets the forum image url.
        /// </summary>
        [MaxLength(1024)]
        public virtual string ImageUrl { get; set; }

        public  virtual ICollection<Moderator> Moderators { get; set; }

        ///// <summary>
        ///// Gets/Sets the Posts
        ///// </summary>
        //public virtual ICollection<Post> Posts { get; set; }

        /// <summary>
        /// Gets/Sets the Threads.
        /// </summary>
        public virtual ICollection<Thread> Threads { get; set; }

        //[NotMapped]
        //public virtual Post LastPost
        //{
        //    get
        //    {
        //        if (LastPostID.HasValue)
        //        {
        //            return Posts.FirstOrDefault(p => p.ID == LastPostID.Value);
        //        }
        //        return null;
        //    }
        //}
    }
}
